package com.cl.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cl.safe.R;

public class SettingItemView extends RelativeLayout {
	private static final String TAG = "SettingItemView";
	/**
	 * 我们自定义的组合控件，它里面有两个TextView ，还有一个CheckBox,还有一个View
	 * @author Administrator
	 *
	 */
	private CheckBox cb_status;
	private TextView tv_desc;
	private TextView tv_title;
	private String desc_on;
	private String desc_off;
	private String title;
	/**
	 * 初始化布局文件
	 * @param context
	 */
	private void iniView(Context context) {
		
		//把一个布局文件---》View 并且加载在SettingItemView
		View.inflate(context, R.layout.item_4setting, this);
		cb_status = (CheckBox) this.findViewById(R.id.cb_status);
		tv_desc = (TextView) this.findViewById(R.id.tv_desc);
		tv_title = (TextView) this.findViewById(R.id.tv_title);
		
	}
	public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
		iniView(context);
	}

	public SettingItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		iniView(context);
		title = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "title");
		desc_on = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "desc_on");
		desc_off = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "desc_off");
		tv_title.setText(title);
		tv_desc.setText(desc_off);
		System.out.println("标题："+title);
		System.out.println("desc_on："+desc_on);
		System.out.println("desc_off："+desc_off);
	}

	public SettingItemView(Context context) {
		super(context);
		iniView(context);
	}
	/**
	 * 校验组合控件是否选中
	 */
	
	public boolean isChecked(){
		return cb_status.isChecked();
	}
	
	/**
	 * 设置组合控件的状态
	 */
	
	public void setChecked(boolean checked){
		cb_status.setChecked(checked);
		if(checked) {
			setDesc(desc_on);
		}else {
			setDesc(desc_off);
		}
	}
	/**
	 * 设置 组合控件的描述信息
	 */
	
	public void setDesc(String text) {
		tv_desc.setText(text);
	}
}
